home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWRRcShp.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  6.7 KB  |  234 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWRRcShp.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWRRCSHP_H
  13. #include "FWRRcShp.h"
  14. #endif
  15.  
  16. #ifndef FWGC_H
  17. #include "FWGC.h"
  18. #endif
  19.  
  20. #ifndef FWGRGLOB_H
  21. #include "FWGrGlob.h"
  22. #endif
  23.  
  24. #ifndef FWGRUTIL_H
  25. #include "FWGrUtil.h"
  26. #endif
  27.  
  28. #ifndef FWFXMATH_H
  29. #include "FWFxMath.h"
  30. #endif
  31.  
  32. #ifndef FWRASTER_H
  33. #include "FWRaster.h"
  34. #endif
  35.  
  36. // ----- Foundation Includes -----
  37.  
  38. #ifndef FWSTREAM_H
  39. #include "FWStream.h"
  40. #endif
  41.  
  42. //========================================================================================
  43. //    RunTime Info
  44. //========================================================================================
  45.  
  46. #if FW_LIB_EXPORT_PRAGMAS
  47. #pragma lib_export on
  48. #endif
  49.  
  50. #ifdef FW_BUILD_MAC
  51. #pragma segment FWGraphics_RoundRectShape
  52. #endif
  53.  
  54. FW_DEFINE_CLASS_M1(FW_CRoundRectShape, FW_CBoundedShape)
  55.  
  56. FW_REGISTER_ARCHIVABLE_CLASS(FW_LRoundRectShape, FW_CRoundRectShape, FW_CRoundRectShape::Read, FW_CShape::Write)
  57.  
  58. //========================================================================================
  59. //    class FW_CRoundRectShape
  60. //========================================================================================
  61.  
  62. //----------------------------------------------------------------------------------------
  63. //    FW_CRoundRectShape::FW_CRoundRectShape
  64. //----------------------------------------------------------------------------------------
  65.  
  66. FW_CRoundRectShape::FW_CRoundRectShape(const FW_CRoundRectShape& other) :
  67.     FW_CBoundedShape(other),
  68.     fOvalSize(other.fOvalSize)
  69. {
  70.     FW_END_CONSTRUCTOR
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. //    FW_CRoundRectShape::FW_CRoundRectShape
  75. //----------------------------------------------------------------------------------------
  76.  
  77. FW_CRoundRectShape::FW_CRoundRectShape(const FW_CRect& rect,
  78.                                        const FW_CPoint& ovalSize,
  79.                                        FW_ERenderVerbs renderVerb,
  80.                                        const FW_PInk& ink,
  81.                                        const FW_PStyle& style) :
  82.     FW_CBoundedShape(rect, renderVerb, ink, style, FW_kNormalFont),
  83.     fOvalSize(ovalSize)
  84. {
  85.     FW_END_CONSTRUCTOR
  86. }
  87.  
  88. //----------------------------------------------------------------------------------------
  89. //    FW_CRoundRectShape::FW_CRoundRectShape
  90. //----------------------------------------------------------------------------------------
  91.  
  92. FW_CRoundRectShape::FW_CRoundRectShape(FW_CReadableStream& archive) :
  93.     FW_CBoundedShape(archive)
  94. {
  95.     archive >> fOvalSize;
  96.     FW_END_CONSTRUCTOR
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //    FW_CRoundRectShape::~FW_CRoundRectShape
  101. //----------------------------------------------------------------------------------------
  102.  
  103. FW_CRoundRectShape::~FW_CRoundRectShape()
  104. {
  105.     FW_START_DESTRUCTOR
  106. }
  107.  
  108. //----------------------------------------------------------------------------------------
  109. //    FW_CRoundRectShape::operator=
  110. //----------------------------------------------------------------------------------------
  111.  
  112. FW_CRoundRectShape& FW_CRoundRectShape::operator=(const FW_CRoundRectShape& other)
  113. {
  114.     if (this != &other)
  115.     {
  116.         FW_CBoundedShape::operator=(other);    
  117.         fOvalSize = other.fOvalSize;
  118.     }
  119.     
  120.     return *this;
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_CRoundRectShape::Render
  125. //----------------------------------------------------------------------------------------
  126.  
  127. void FW_CRoundRectShape::Render(FW_CGraphicContext& gc) const
  128. {    
  129.     gc.GetRasterizer()->RenderRoundRect(gc,
  130.                                         fRect, fOvalSize,
  131.                                         GetRenderVerb(),
  132.                                         fInk,
  133.                                         fStyle);
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    FW_CRoundRectShape::RenderRoundRect
  138. //----------------------------------------------------------------------------------------
  139.  
  140. void FW_CRoundRectShape::RenderRoundRect(FW_CGraphicContext& gc,
  141.                                         const FW_CRect& rect, 
  142.                                         const FW_CPoint& ovalSize,
  143.                                         FW_ERenderVerbs renderVerb, 
  144.                                         const FW_PInk& ink,
  145.                                         const FW_PStyle& style)
  146. {    
  147.     gc.GetRasterizer()->RenderRoundRect(gc,
  148.                                         rect, ovalSize,
  149.                                         renderVerb,
  150.                                         ink,
  151.                                         style);
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. //    FW_CRoundRectShape::HitTest
  156. //----------------------------------------------------------------------------------------
  157.  
  158. FW_Boolean FW_CRoundRectShape::HitTest(FW_CGraphicContext& gc,
  159.                                        const FW_CPoint& test,
  160.                                        FW_CFixed tolerance) const
  161. {
  162. FW_UNUSED(gc);
  163.  
  164.     if(fRenderVerb == FW_kNoRendering)
  165.         return FALSE;
  166.  
  167.     FW_CRect bounds(fRect);
  168.     bounds.Inset(-tolerance, -tolerance);
  169.     
  170.     if(::FW_PtInRoundRect(bounds, fOvalSize, test))
  171.     {
  172.         if (fRenderVerb == FW_kFrame)
  173.         {            
  174.             FW_CFixed inset = tolerance + GetPenSize();
  175.             bounds = fRect;
  176.             bounds.Inset(inset, inset);
  177.             return !::FW_PtInRoundRect(bounds, fOvalSize, test);
  178.         }
  179.  
  180.         return TRUE;
  181.     }
  182.  
  183.     return FALSE;
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    FW_CRoundRectShape::Copy
  188. //----------------------------------------------------------------------------------------
  189.  
  190. FW_CShape* FW_CRoundRectShape::Copy() const
  191. {
  192.     return FW_NEW(FW_CRoundRectShape, (*this));
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196. //    FW_CRoundRectShape::GetGeometry
  197. //----------------------------------------------------------------------------------------
  198.  
  199. void FW_CRoundRectShape::GetGeometry(FW_CRect& rect, FW_CPoint& ovalSize) const
  200. {
  201.     ovalSize = fOvalSize;
  202.     rect = fRect;
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    FW_CRoundRectShape::SetGeometry
  207. //----------------------------------------------------------------------------------------
  208.  
  209. void FW_CRoundRectShape::SetGeometry(const FW_CRect& rect, const FW_CPoint& ovalSize)
  210. {
  211.     fOvalSize = ovalSize;
  212.     fRect = rect;
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    FW_CRoundRectShape::Flatten
  217. //----------------------------------------------------------------------------------------
  218.  
  219. void FW_CRoundRectShape::Flatten(FW_CWritableStream& archive) const
  220. {
  221.     FW_CBoundedShape::Flatten(archive);
  222.     archive << fOvalSize;
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. //    FW_CRoundRectShape::Read
  227. //----------------------------------------------------------------------------------------
  228.  
  229. void* FW_CRoundRectShape::Read(FW_CReadableStream& archive)
  230. {
  231.     return FW_NEW(FW_CRoundRectShape, (archive));
  232. }
  233.  
  234.